package com.cpecc.manager.system;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cpecc.dao.system.DepDao;
import com.cpecc.model.system.Dep;

@Service
public class DepManager {

	@Autowired
	private DepDao depDao;
	
	private List<Dep> result;
	
	private void preOrder(Dep root){
		result.add(root);
		for(Dep d:root.getChilds()){
			preOrder(d);
		}
	}
	
	public List<Dep> getAllDep(){
		result=new ArrayList<Dep>();
		Dep root=depDao.getRoot();
		preOrder(root);
		return result;
	}
	
	public Dep get(String id){
		return depDao.get(id);
	}
	
	public int getChildSize(String pId){
		return depDao.getChildSize(pId);
	}
	
	public boolean getByDaiMa(String daiMa){
		return depDao.getByDaiMa(daiMa);
	}
	
	public boolean cover(Dep dep){
		return depDao.cover(dep);
	}
	
	public void save(Dep dep){
		depDao.save(dep);
	}
	
	public boolean hasChild(Dep dep){
		return depDao.hasChild(dep);
	}
	
	public void delete(Dep dep){
		depDao.delete(dep);
	}
}
